package com.example.springboot_manage.service.impl;

import com.example.springboot_manage.model.ShoeCategory;
import com.example.springboot_manage.repository.CategoryRepository;
import com.example.springboot_manage.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryRepository categoryRepository;
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Value("category.list.key")
    private List categoryListKey;

    @Override
    public Integer delCategory(Integer id) {

        redisTemplate.delete(redisTemplate.keys("category*"));

        return categoryRepository.deleteById(id);
    }

    @Override
    public Integer updateCategory(ShoeCategory shoeCategory) {
        redisTemplate.delete(redisTemplate.keys("category*"));
        return categoryRepository.update(shoeCategory);
    }

    @Override
    public Integer saveCategory(ShoeCategory shoeCategory) {
        redisTemplate.delete(redisTemplate.keys("category*"));
        return categoryRepository.save(shoeCategory);
    }
}
